<template>
  <div class="my-tag" @dblclick="qiehuan">
    <input
      class="input"
      type="text"
      placeholder="输入标签"
      v-if="isShow"
      v-focuss
      @blur="close"
      @keydown.enter="close"
      v-model="tag"
    />
    <div v-else class="text">{{ value }}</div>
  </div>
</template>

<script>
export default {
  props: ['value'],
  data() {
    return {
      isShow: false,
      tag: '',
    }
  },
  methods: {
    qiehuan() {
      this.isShow = true
      this.tag = this.value
    },
    close() {
      this.isShow = false
      this.$emit('input', this.tag)
    },
  },
  directives: {
    focuss: {
      inserted(e) {
        e.focus()
      },
    },
  },
}
</script>

<style></style>
